package hlhj.fhp.supreme.activitys

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.app.ActivityOptionsCompat
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import hlhj.fhp.supreme.BaseAty
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.ExtensionBean
import hlhj.fhp.supreme.network.Urls
import hlhj.fhp.supreme.utils.JsonCallBack
import kotlinx.android.synthetic.main.activity_join_extension_aty.*

class JoinExtensionAty : BaseAty() {
    override fun getContentId(): Int {
        return R.layout.activity_join_extension_aty
    }

    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
        btGetCash.setOnClickListener {
            startActivity(Intent(this,GetCashAty::class.java))
        }
        btMyExtension.setOnClickListener {
            startActivity(Intent(this,MyExtension::class.java))
        }
        btImg.setOnClickListener {
            val intent = Intent(this, EwmAty::class.java)
            intent.putExtra("type",1)
            startActivity(intent,ActivityOptionsCompat.makeSceneTransitionAnimation(this,btImg,"ewmImg").toBundle())
        }
    }

    override fun initView() {
        OkGo.post<ExtensionBean>(Urls.BaseUrl+Urls.MY_EXTENSION)
                .execute(object :JsonCallBack<ExtensionBean>(this){
                    override fun onSuccess(response: Response<ExtensionBean>?) {
                        val bean = response?.body()
                        if (bean?.code==1){
                            tv0.text="我的推广码：${bean?.data.friend_code}"
                            tv1.text="推广总金额：${bean?.data.order_sum.toString()}"
                            tv2.text="提成金额：${bean?.data.marketing_sum}"
                            listView.adapter=object :BaseQuickAdapter<String,BaseViewHolder>(R.layout.extension_item,bean?.data.str){
                                override fun convert(helper: BaseViewHolder?, item: String?) {
                                    helper?.setText(R.id.itemTv,item)
                                }
                            }
                            listView.layoutManager=LinearLayoutManager(this@JoinExtensionAty,LinearLayoutManager.VERTICAL,false)
                        }
                    }
                })

    }

}
